#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QTimer>
#include <QDebug>
#include <QThread>

#include "simplethreadone.h"
#include "myqmlclass.h"
#include "mytimer.h"
#include "newspaper.h"
#include "reader.h"

int glabal_value = 0;
MyQmlClass myQmlImp;

//定时器约定
int scp_torpedsim_timer_5ms = 0;
int scp_torpedsim_timer_10ms = 0;


int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    // 定时器
    //MyTimer mytimer;

    // 方式一：注册定义好的对象到 QML
    engine.rootContext()->setContextProperty("myQmlImp", &myQmlImp);

    /*
     * 开启线程
    SimpleThreadOne *SThread = new SimpleThreadOne();
    SThread->start();
    */

    // 方式二：注册类到 QML 对象
     //qmlRegisterType<MyQmlClass>("myqmlclass", 1, 0, "MyQmlClass");

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    // 20221004 zd 尝试Qt信号槽
    Newspaper newspaper("Newspaper A dong");
    Reader reader;
    QObject::connect(&newspaper, &Newspaper::newPaper,
                     &reader,    &Reader::receiveNewspaper);
    newspaper.send();

    // 第二个参数传的是类的函数
    QObject::connect(&reader, &Reader::count_reader,
                     &newspaper,&Newspaper::count_Paper);
    reader.read_send();

    return app.exec();
}

